<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增')"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-form-item">
                    <label class="layui-form-label">博客</label>
                    <div class="layui-input-block">
                        <button class="pear-btn pear-btn-primary pear-btn-md" type="button" lay-event="add" id="addFile">
                            <i class="layui-icon layui-icon-add-1"></i>
                            上传
                        </button>
                        <img id="pic_img" src="" width="50px" style="display: none"/>
                        <input type="hidden" id="img" name="img">
                    </div>
                </div>

<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-form-label">主图</label>-->
<!--                    <div class="layui-input-block">-->
<!--                        <input type="text" id="img" name="img"  autocomplete="off" placeholder="请输入主图"-->
<!--                               class="layui-input">-->
<!--                    </div>-->
<!--                </div>-->
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" id="title" name="title"  autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接</label>
                    <div class="layui-input-block">
                        <input type="text" id="link" name="link"  autocomplete="off" placeholder="请输入链接"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="text" id="sort" name="sort"  autocomplete="off" placeholder="请输入排序"
                               class="layui-input">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="banner-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'jquery','laydate'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#birthday' //指定元素
        });


        $("#addFile").on('click', function () {
            layer.open({
                type: 2,
                title: '新增',
                shade: 0.1,
                area: ['500px', '300px'],
                content: '/system/file/add'
            });
        })


        form.on('submit(banner-save)', function (data) {
            $.ajax({
                url: '/blog/banner/save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("banner-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })

    function perId( id ){
        document.getElementById("pic_img").src = "/system/file/download/"+id;
        document.getElementById("pic_img").style.display="inline-block"
        document.getElementById("img").value=id;
    }

</script>

</body>
</html>